package com.hdwx.weike.service.impl;

import com.hdwx.weike.beans.PageBean;
import com.hdwx.weike.beans.VideoBean;
import com.hdwx.weike.beans.VideoSection;
import com.hdwx.weike.beans.VideoType;
import com.hdwx.weike.dao.VideoDao;
import com.hdwx.weike.service.IVideoService;

import java.util.List;

/**
 * Created by hdwx on 2016/12/24.
 */
public class VideoServiceImpl implements IVideoService{
    VideoDao videoDao=new VideoDao();
    @Override
    public PageBean queryByIndex(int index,int sectionId,int typeId,int sortId) {

        //将分段id、分类id、排序id、页码传给videodao，videodao调用方法查询
        PageBean pageBean1 = videoDao.queryByPageIndex(index,sectionId,typeId,sortId);
        return pageBean1;
    }

    //通过关键字查询该页信息
    @Override
    public PageBean queryByName(String name, int index, int sortId) {
        PageBean pageBean=videoDao.queryByPageName(name,index,sortId);
        return pageBean;
    }
    //查询收藏量最高的前n个视频
    @Override
    public List<VideoBean> queryByCollection() {
        int count=4;//查询前4个
        return videoDao.queryByOrder("v_collections desc",count);
    }
    //通过id将收藏量+1
    @Override
    public boolean updateVideoCollection(int id) {
        int count = videoDao.queryCollectionsById(id);
        if(count!=-1){
            count++;
            Object[] value={count};
            return videoDao.updateById(id,value);
        }
        return false;
    }
    //查询最新的前n个视频
    @Override
    public List<VideoBean> queryNewVideo() {
        int count=6;//查询前6个最新视频
        return videoDao.queryByOrder("insert_time desc",count);
    }


    //查询所有学段
    @Override
    public List<VideoSection> queryAllVideoSection() {
        return videoDao.queryAllSections();
    }
    //查询所有分类
    @Override
    public List<VideoType> queryAllVideoType() {
        return videoDao.queryAllTypes();
    }
}
